package net.alche.fa.core.model;

import java.util.List;
import net.alche.al.util.AC;
import java.util.ArrayList;

//
// Logic
//
@SuppressWarnings("all")
public class Logic {
  public Integer num;
  public Integer lv;
  public String codeStr;
  public FaValue faObjValue;
  public FaValue faDataValue;
  public String obj;
  public String what;
  public Logic logicObj;
  public String eq;
  public String data;
  public Logic logicData;
  public List<Logic> plus;
  public List<Logic> param;
  public String back;
  public List<Logic> child;

  public Logic() {
  }

  public Logic(String what) {
    this.what = what;
  }

  public Logic(List<Logic> child) {
    this.child = child;
  }

  public Logic newSubLogic() {
    Logic gic = new Logic();
    if (obj == null && logicObj == null) {
      setLogicObj(gic);
    } else {
      setLogicData(gic);
    }
    return gic;
  }

  public boolean hasObj() {
    return AC.isNotEmpty(this.obj) || this.logicObj != null;
  }

  public boolean hasData() {
    return AC.isNotEmpty(this.data) || this.logicData != null;
  }

  private boolean whatFirst() {
    if (what == null) {
      return false;
    }
    if ("if,for,util,var,else,?:,&,|,!,fmt,return,switch,sys.out".contains(what) || what.startsWith("var")) {
      if (what.equals(".")) {
        return false;
      }
      return true;
    }
    return false;
  }

  public boolean hasValueData() {
    if (this.data == null && this.obj == null && this.logicObj == null && this.logicData == null && this.what == null
        && (this.getPlus() == null || this.getPlus().isEmpty())) {
      return false;
    }
    return true;
  }

  public Logic toSelfObj() {
    return toSelf("obj");
  }

  public Logic toSelfData() {
    return toSelf("data");
  }

  public void fillLogic(Logic g) {
    this.setObj(g.getObj());
    this.setLogicObj(g.getLogicObj());
    this.setData(g.getData());
    this.setLogicData(g.getLogicData());
    this.setWhat(g.getWhat());
  }

  public Logic toSelf(String type) {
    Logic toLogic = new Logic();
    toLogic.setObj(this.getObj());
    toLogic.setLogicObj(this.getLogicObj());
    toLogic.setData(this.getData());
    toLogic.setLogicData(this.getLogicData());
    toLogic.setWhat(this.getWhat());
    this.setWhat(null);
    this.setObj(null);
    this.setLogicObj(null);
    this.setData(null);
    this.setLogicData(null);
    if (type.equals("obj")) {
      this.setLogicObj(toLogic);
    } else {
      this.setLogicData(toLogic);
    }
    return toLogic;
  }

  public Logic addChild(Logic logic) {
    if (this.child == null) {
      this.child = new ArrayList<>();
    }
    this.child.add(logic);
    return this;
  }

  public Logic addPlus(Logic logic) {
    if (this.plus == null) {
      this.plus = new ArrayList<>();
    }
    this.plus.add(logic);
    return this;
  }

  public Logic addParam(Logic logic) {
    if (this.param == null) {
      this.param = new ArrayList<>();
    }
    this.param.add(logic);
    return this;
  }

  public List<Logic> getChild() {
    return child;
  }

  public void setChild(List<Logic> child) {
    this.child = child;
  }

  public String getBack() {
    return back;
  }

  public void setBack(String back) {
    this.back = back;
  }

  public String getWhat() {
    return what;
  }

  public void setWhat(String what) {
    this.what = what;
  }

  public String getObj() {
    return obj;
  }

  public Logic setObj(String obj) {
    this.obj = obj;
    return this;
  }

  public String getEq() {
    return eq;
  }

  public void setEq(String eq) {
    this.eq = eq;
  }

  public Logic getLogicObj() {
    return logicObj;
  }

  public void setLogicObj(Logic logicObj) {
    this.logicObj = logicObj;
  }

  public String getData() {
    return data;
  }

  public void setData(String data) {
    this.data = data;
  }

  public Logic getLogicData() {
    return logicData;
  }

  public void setLogicData(Logic logicData) {
    this.logicData = logicData;
  }

  public List<Logic> getParam() {
    return param;
  }

  public void setParam(List<Logic> param) {
    this.param = param;
  }

  public List<Logic> getPlus() {
    return plus;
  }

  public void setPlus(List<Logic> plus) {
    this.plus = plus;
  }

  public String getCodeStr() {
    return codeStr;
  }

  public void setCodeStr(String codeStr) {
    this.codeStr = codeStr;
  }

  public Integer getNum() {
    return num;
  }

  public void setNum(Integer num) {
    if (num < 0) {
      return;
    }
    this.num = num;
  }

  public Integer getLv() {
    return lv;
  }

  public void setLv(Integer lv) {
    if (lv < 0) {
      return;
    }
    this.lv = lv;
  }

  public FaValue getFaDataValue() {
    return faDataValue;
  }

  public void setFaDataValue(FaValue faDataValue) {
    this.faDataValue = faDataValue;
  }

  public FaValue getFaObjValue() {
    return faObjValue;
  }

  public void setFaObjValue(FaValue faObjValue) {
    this.faObjValue = faObjValue;
  }
}